package com.lsh.quartz.config;

import com.lsh.quartz.job.Job;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail JobDetail(){
        return JobBuilder.newJob(Job.class)
                .withIdentity("deleteImg")
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger JobTrigger(){
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 4 * * ? *");//凌晨四点执行
        return TriggerBuilder.newTrigger()
                .forJob(JobDetail())//上面方法名称
                .withIdentity("JobTrigger")//给trigger起个名字
                .withSchedule(cronScheduleBuilder)//七子表达式
                .build();
    }
}
